package com.sunfeng.chap2.p13;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/**
 * @Author : 孙峰
 * @Description: 验证共享锁 别人不能写
 * @Date : 2021/10/9  16:37
 */
public class Test13_7 {

    private  static RandomAccessFile randomAccessFile;

    private static FileChannel fileChannel;

    public static void main(String[] args) throws IOException, InterruptedException {
        randomAccessFile=new RandomAccessFile("d:\\nio\\a.txt","rw");
        fileChannel=randomAccessFile.getChannel();
        fileChannel.lock(1,2,true);
        Thread.sleep(Integer.MAX_VALUE);
    }
}
